<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
  <title>部门列表</title>
  <style>
    body { font-family: Arial, sans-serif; background-color: #f5f5f5; }
    .container { width: 90%; margin: 0 auto; }
    .header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
    h1 { color: #333; }
    .btn { padding: 10px 15px; background-color: #4CAF50; color: white; border: none; border-radius: 4px; cursor: pointer; text-decoration: none; }
    .btn:hover { background-color: #45a049; }
    table { width: 100%; border-collapse: collapse; background: white; box-shadow: 0 0 10px rgba(0,0,0,0.1); }
    th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid #ddd; }
    th { background-color: #4CAF50; color: white; }
    tr:hover { background-color: #f5f5f5; }
    .pagination { display: flex; justify-content: center; margin-top: 20px; }
    .pagination a { display: inline-block; padding: 8px 16px; text-decoration: none; color: #333; border: 1px solid #ddd; margin: 0 4px; }
    .pagination a.active { background-color: #4CAF50; color: white; border: 1px solid #4CAF50; }
    .pagination a:hover:not(.active) { background-color: #ddd; }
    .info-bar { margin: 10px 0; color: #666; font-size: 14px; }
    .nav-links { display: flex; gap: 10px; margin-bottom: 20px; }
    .nav-link { padding: 8px 15px; background: #2196F3; color: white; text-decoration: none; border-radius: 4px; }

    .btn-edit, .btn-delete {
      padding: 5px 10px;
      text-decoration: none;
      border-radius: 3px;
      font-size: 14px;
      display: inline-block;
      margin-right: 5px;
    }

    .btn-edit {
      background-color: #2196F3;
      color: white;
    }

    .btn-delete {
      background-color: #f44336;
      color: white;
    }

    .btn-edit:hover {
      background-color: #0b7dda;
    }

    .btn-delete:hover {
      background-color: #da190b;
    }
  </style>
</head>
<body>
<div class="container">
  <div class="nav-links">
    <a href="employees" class="nav-link">员工</a>
    <a href="departments" class="nav-link">部门</a>
    <a href="salaries" class="nav-link">工资</a>
  </div>

  <div class="header">
    <h1>部门列表</h1>
    <a href="addDepartment" class="btn">添加新部门</a>
  </div>

  <div class="info-bar">
    全部部门: ${totalDepartments}
  </div>

  <table>
    <thead>
    <tr>
      <th>ID</th>
      <th>名称</th>
      <th>管理人员</th>
      <th>地点</th>
      <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${departments}" var="dept">
      <tr>
        <td>${dept.deptId}</td>
        <td>${dept.deptName}</td>
        <td>${dept.manager}</td>
        <td>${dept.location}</td>
        <td>
          <a href="editDepartment?id=${dept.deptId}" class="btn-edit">编辑</a>
          <a href="deleteDepartment?id=${dept.deptId}" class="btn-delete"
             onclick="return confirm('Are you sure you want to delete this department?')">删除</a>
      </tr>
    </c:forEach>
    </tbody>
  </table>
</div>
</body>
</html>
